<template>
  <BasicModal
    width="700px"
    destroyOnClose
    @register="registerModal"
    title="修改下级"
    layout="vertical"
    @ok="handleAddUser"
  >
    <BasicForm @register="register" />
  </BasicModal>
</template>

<script lang="ts" setup>
  import { BasicModal, useModalInner } from '@/components/Modal';
  import { BasicForm, useForm } from '@/components/Form';
  import { AddAgentApi } from '@/api/group';
  import message from '@/views/form-design/utils/message';

  const [registerModal, { closeModal }] = useModalInner();
  const [register, { getFieldsValue }] = useForm({
    showActionButtonGroup: false,
    schemas: [
      {
        field: 'nickname',
        label: '代理昵称',
        component: 'Input',
        colProps: { span: 24 },
        componentProps: {
          placeholder: '请输入代理昵称',
        },
      },
      {
        field: 'username',
        label: '代理账号',
        component: 'Input',
        colProps: { span: 24 },
        componentProps: {
          placeholder: '请输入代理账号',
        },
      },
      {
        field: 'password',
        label: '登录密码',
        component: 'Input',
        colProps: { span: 24 },
        componentProps: {
          placeholder: '请输入登录密码',
        },
      },
      {
        field: 'contact',
        label: '联系方式',
        component: 'Input',
        colProps: { span: 24 },
        componentProps: {
          placeholder: '请输入联系方式（可为空）',
        },
      },
    ],
  });

  const handleAddUser = () => {
    const params = getFieldsValue();
    AddAgentApi(params).then(() => {
      message.success('添加成功');
      closeModal();
    });
  };
</script>
